package com.example.dp01.service;

import com.example.dp01.dao.TeacherRepository;
import com.example.dp01.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherService {

    @Autowired
    public TeacherRepository teacherRepository;

    public List<Teacher> getAll() {
        return teacherRepository.findAll();
    }

    /**新增
     *
     * @param teacher
     * @return
     */

    public Teacher add(Teacher teacher){ return teacherRepository.save(teacher);
}
    /**
     * 更新
     */
    public Teacher update(Teacher teacher){
        return teacherRepository.save(teacher);
    }
    /**
     * 删除
     */
    public void  delete(Integer id){
        teacherRepository.deleteById(id);
    }
    /**
     * 按ID查询
     * @param id
     * @return
     */
    public Teacher findById(int id) {
        return teacherRepository.findById(id).get();

    }
    /**
     * 按姓名查询
     *
     * @return
     */
    public List<Teacher> findByName(String name) {
        return teacherRepository.findByNameLike(name);

    }
    public void Insert(Teacher teacher) {
        teacherRepository.save(teacher);
    }

    public void Update(Teacher teacher) {
        teacherRepository.save(teacher);
    }



}
